import { Table } from "element-ui";
import Vue from 'vue'

const TableStore=function(table,initialState={}){

    this.table=table;

    this.states={
        columns:[],
        data:[],
    }

    for (let prop in initialState) {
        if (initialState.hasOwnProperty(prop) && this.states.hasOwnProperty(prop)) {
            this.states[prop] = initialState[prop];
        }
    }
}

TableStore.prototype.setStates=function(initialState={}){
    for (let prop in initialState) {
        if (initialState.hasOwnProperty(prop) && this.states.hasOwnProperty(prop)) {
            this.states[prop] = initialState[prop];
        }
    }
}

TableStore.prototype.commit = function(name, ...args) {
    const mutations = this.mutations;
    if (mutations[name]) {
      mutations[name].apply(this, [this.states].concat(args));
    } else {
      throw new Error(`Action not found: ${name}`);
    }
};

export default TableStore;